package com.compass.doctor.ui.message.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.compass.doctor.R
import com.compass.doctor.databinding.LayoutNotificationItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.gone
import com.compass.framework.ext.visible
import com.compass.framework.manager.DictionariesManager
import com.compass.framework.model.Message
import com.compass.framework.utils.DateUtils
import com.compass.framework.utils.getDrawableResource

/**
 * Description： 通知adapter
 * Date:2023/12/7 15:05
 */
class NotificationAdapter : BaseRecyclerViewAdapter<Message, LayoutNotificationItemBinding>() {
    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutNotificationItemBinding>,
        item: Message?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvTitle.text = DictionariesManager.getNotificationTypeString(item.type)
            tvTime.text = DateUtils.getTimeDescriptionByDate(item.createTime)
            tvContent.text= item.title
            if (item.readStatus==1) imgIsRead.gone() else imgIsRead.visible()

            when (item.type) {//根据类型匹配
                "4","12" -> {
                    ivNotification.background = (getDrawableResource(R.drawable.bg_oval_yellow))
                    ivNotification.setImageResource(R.mipmap.icon_wd_notification)
                }

                "2","9" -> {
                    ivNotification.background = (getDrawableResource(R.drawable.bg_oval_green))
                    ivNotification.setImageResource(R.mipmap.icon_flow_notification)
                }

                else -> {
                    ivNotification.background = (getDrawableResource(R.drawable.bg_oval_blue))
                    ivNotification.setImageResource(R.mipmap.icon_sys_notification)
                }

            }


        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutNotificationItemBinding {
        return LayoutNotificationItemBinding.inflate(layoutInflater, parent, false)
    }
}